package org.ielse.frame.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

import org.ielse.frame.App;

public class NetworkUtil {

	public final static int NONE = 0;
	public final static int WIFI = 1;
	public final static int MOBILE = 2;

	public static int getNetworkState() {
		ConnectivityManager connManager = (ConnectivityManager) App.i().getSystemService(Context.CONNECTIVITY_SERVICE);

		// GPRS
		State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
		if (state == State.CONNECTED || state == State.CONNECTING) {
			return MOBILE;
		}

		// WIFI
		state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
		if (state == State.CONNECTED || state == State.CONNECTING) {
			return WIFI;
		}

		return NONE;
	}

	public static boolean isNoInternet() {
		return NONE == getNetworkState();
	}

	public static boolean isWiFiOpened() {
		return WIFI == getNetworkState();
	}
	
	public static boolean isGPRSOpened() {
		return MOBILE == getNetworkState();
	}
}
